package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.enums.SysPermissionEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.ExcelModelVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.common.vo.org.OrgVO;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.helper.ExcelCommonHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.base.core.integration.OperationPeriodIntegration;
import com.bifang.module.system.core.dao.model.SysOrg;
import com.bifang.module.system.core.dao.service.SysOrgService;
import com.bifang.module.system.core.integration.OrgIntegration;
import com.bifang.module.system.core.integration.impl.ExcelIntegrationImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.EnrollStatusEnum;
import com.jwsoft.manager.common.enums.SchoolCategoryEnum;
import com.jwsoft.manager.common.enums.SchoolConfigDictEnum;
import com.jwsoft.manager.common.enums.SchoolDictEnum;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduSchool.*;
import com.jwsoft.manager.common.vo.eduSchoolConfig.EduSchoolConfigVO;
import com.jwsoft.manager.core.dao.model.EduArea;
import com.jwsoft.manager.core.dao.model.EduSchool;
import com.jwsoft.manager.core.dao.model.EduSchoolBb;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduSchoolIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 所属学校表业务实现类
 *
 * @author wangtao
 * @since 2022-11-25
 */
@ApiService(funcCode = "eduschool", title = "所属学校表")
public class EduSchoolIntegrationImpl implements EduSchoolIntegration {

    @Autowired
    public EduSchoolService eduSchoolService;

    @Autowired
    private OrgIntegration orgIntegration;

    @Autowired
    private SysOrgService sysOrgService;

    @Autowired
    private EduAreaService eduAreaService;

    @Autowired
    public DictHelper dictHelper;
    @Autowired
    public CommonIntegration commonIntegration;

    @Resource
    public OperationPeriodIntegration operationPeriodIntegration;

    @Autowired
    public ExcelIntegrationImpl excelIntegration;
    @Value("${spring.servlet.multipart.location}")
    private String tempPath;

    @Autowired
    ExcelCommonHelper excelCommonHelper;
    @Autowired
    EduHelper eduHelper;
    @Autowired
    EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    EduSchoolConfigService eduSchoolConfigService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;

    @Autowired
    private DictIntegration dictIntegration;
    @Autowired
    private EduSchoolBbService eduSchoolBbService;

    @Autowired
    private EduDataTaskDetailService eduDataTaskDetailService;

    public static final String handleTable = "edu_student_enroll_pre";
    @Override
    @OpApi(funcCode = "eduschool0001", title = "管理端所属学校表分页查询", funcType = FuncTypeEnum.query,checkPrivilege =BoolEnum.FALSE)
    public PageInfo<EduSchoolVO> getList(@NotNull EduSchoolQueryVO vo) {
        if (StringUtils.isNotBlank(vo.getShortName())) {
            vo.setShortName(Convert.toDBC(vo.getShortName()));
        }
        if (StringUtils.isNotBlank(vo.getSchoolName())) {
            vo.setSchoolName(Convert.toDBC(vo.getSchoolName()));
        }
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        List<EduSchoolVO> eduSchoolList = querySchoolInfo(vo);
        if (CollectionUtils.isEmpty(eduSchoolList)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        List<String> streetList = eduSchoolList.stream().map(EduSchoolVO::getStreet).distinct().collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(streetList)) {
            QueryWrapper<EduArea> areaQueryWrapper = new QueryWrapper<>();
            areaQueryWrapper.lambda().in(EduArea::getLocalCode, streetList);
            List<EduArea> areaList =
                    eduAreaService.list(areaQueryWrapper);

            Map<String, String> streetMap = areaList.stream().collect(Collectors.toMap(EduArea::getLocalCode, EduArea::getAreaName));
            for (EduSchoolVO eduSchoolVO : eduSchoolList) {
                if (!ObjectUtils.isEmpty(eduSchoolVO.getStreet())) {
                    eduSchoolVO.setStreetName(streetMap.get(eduSchoolVO.getStreet()));
                }
            }
        }


        // 不为空则获取分页结果
        PageInfo<EduSchoolVO> pageInfo = new PageInfo<>(eduSchoolList);
        List<EduSchoolVO> resList = pageInfo.getList();

        dictHelper.valueToName(resList, Arrays.asList(SchoolDictEnum.values()));
        for (EduSchoolVO eduSchoolVO : resList) {
            eduSchoolVO.setAreaName(dictHelper.getAreaNameByCode(eduSchoolVO.getAreaCode()));
        }

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduschool0002", title = "所属学校表根据主键查询详情-校验招生计划", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public EduSchoolVO getById(EduSchoolKeyVO vo) {
        if (StringUtils.isBlank(vo.getOrgId())) {
            throw new AppException("学校id不能为空");
        }
        EduSchoolVO result = eduSchoolService.getDetail(vo.getOrgId());
        if (ObjectUtils.isEmpty(result)) {
            throw new AppException("查询不到学校信息!");
        }
        long curTime = DateUtil.currentSeconds();
        Integer year = eduHelper.thisYear();
        List<EduSchoolConfigVO> configList = result.getConfigList();
        if (!CollectionUtils.isEmpty(configList)) {
            if ("1".equals(result.getSchoolCategory())) {
                int stopNum = 0;
                Date startTime = configList.get(0).getStartTime();
                Date endTime = configList.get(0).getEndTime();
                for (int i = 0; i < result.getConfigList().size(); i++) {
                    long startT = configList.get(i).getStartTime().getTime() / 1000;
                    long endT = configList.get(i).getEndTime().getTime() / 1000;
                    if (DateUtil.compare(
                            startTime, configList.get(i).getStartTime())
                            > 0) {
                        startTime = configList.get(i).getStartTime();
                    }
                    if (DateUtil.compare(endTime, configList.get(i).getEndTime())
                            < 0) {
                        endTime = configList.get(i).getEndTime();
                    }
                    if (DateUtil.compare(
                            configList.get(i).getEndTime(), DateUtil.date())
                            < 0) {
                        stopNum++;
                        configList
                                .get(i)
                                .setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        if (curTime < startT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.wait.getType());
                        } else if (curTime > endT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.finish.getType());
                        } else {
                            configList
                                    .get(i)
                                    .setEnrollStatus(EnrollStatusEnum.on.getType());
                        }
                    }
                }
                result.setStartTime(startTime);
                result.setEndTime(endTime);
                if (stopNum == configList.size()) {
                    result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                } else {
                    long startT = startTime.getTime() / 1000;
                    long endT = endTime.getTime() / 1000;
                    if (curTime < startT) {
                        result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                    } else if (curTime > endT) {
                        result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        result.setEnrollStatus(EnrollStatusEnum.on.getType());
                    }
                }
                result.setConfigList(configList);
            } else {
                EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
                queryVO.setClassify("2");
                queryVO.setAreaCode(result.getAreaCode());
                queryVO.setYear(year);
                EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
                if (eduOperationCacheVO == null) {
                    throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
                }
                Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
                EduOperationCacheDetailVO bmOperation = operation.get("YW002");//报名时间
                EduOperationCacheDetailVO bbOperation = operation.get("YW022");//补报时间
                EduOperationCacheDetailVO qbOperation = operation.get("YW010");//抢报时间
                EduOperationCacheDetailVO bmxxOperation=operation.get("YW066");//第一批小学报名业务期
                EduOperationCacheDetailVO bmczOperation=operation.get("YW067");//第一批初中报名业务期
                EduOperationCacheDetailVO bbxxOperation=operation.get("YW068");//第二批小学报名业务期
                EduOperationCacheDetailVO bbczOperation=operation.get("YW069");//第二批初中报名业务期
                EduOperationCacheDetailVO qbxxOperation=operation.get("YW070");//第三批小学报名业务期
                EduOperationCacheDetailVO qbczOperation=operation.get("YW071");//第三批初中报名业务期
                EduOperationCacheDetailVO bbTwoOperation=operation.get("YW072");//第二批第二轮
                EduOperationCacheDetailVO bbxxTwoOperation=operation.get("YW073");//第二批第二轮小学
                EduOperationCacheDetailVO bbczTwoOperation=operation.get("YW074");//第二批第二轮初中
                CommonVO commonTwoVO = new CommonVO();
                commonTwoVO.setParamKey("BM_DEP_DC");
                String twoFlagStr = commonIntegration.getValueByKey(commonTwoVO);
                boolean bbTwo= false;
                if ("1".equalsIgnoreCase(twoFlagStr) || "true".equalsIgnoreCase(twoFlagStr)) {
                    bbTwo = true;
                }
                //判断是否报名业务期
                boolean bmFlag = bmOperation == null ? false : bmOperation.isFlag();
                //判断是否补报业务期
                boolean bbFlag = bbOperation == null ? false : bbOperation.isFlag();
                //判断是否空额抢报业务期
                boolean qbFlag = qbOperation == null ? false : qbOperation.isFlag();
                //判断是否第二批第二轮
                boolean bbTwoFlag = bbTwoOperation==null?false:bbTwoOperation.isFlag();
                result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                if (bmOperation != null) {
                    if (!bmOperation.isFlag()) {
                        if ("1".equalsIgnoreCase(bmOperation.getType()) || "3".equalsIgnoreCase(bmOperation.getType())) {
                            result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                        } else {
                            if ("1".equalsIgnoreCase(bbOperation.getType())) {
                                //补报未开始
                                result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                result.setBbFlag(BoolEnum.TRUE.getType());
                            } else if ("3".equalsIgnoreCase(bbOperation.getType())) {
                                result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                            } else {
                                if(bbTwo){
                                    if ("1".equalsIgnoreCase(bbTwoOperation.getType())) {
                                        //第二次补报未开始
                                        result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                        result.setBbFlag(BoolEnum.TRUE.getType());
                                    }else if ("3".equalsIgnoreCase(bbOperation.getType())) {
                                        result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                    } else {
                                        if ("1".equalsIgnoreCase(qbOperation.getType())) {
                                            //抢报未开始
                                            result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                            result.setQbFlag(BoolEnum.TRUE.getType());
                                        } else {
                                            result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                        }
                                    }
                                }else {
                                    if ("1".equalsIgnoreCase(qbOperation.getType())) {
                                        //抢报未开始
                                        result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                        result.setQbFlag(BoolEnum.TRUE.getType());
                                    } else {
                                        result.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                    }
                                }
                            }
                        }
                    }
                } else {
                    result.setEnrollStatus(EnrollStatusEnum.wait.getType());
                }


                if (bbFlag) {
                    result.setEnrollStatus(EnrollStatusEnum.on.getType());
                    result.setStartTime(bbOperation.getBegTime());
                    result.setEndTime(bbOperation.getEndTime());
                    result.setBbFlag(BoolEnum.TRUE.getType());
                    //是否补报
                    QueryWrapper<EduSchoolBb> bbQueryWrapper=new QueryWrapper<>();
                    bbQueryWrapper.lambda().select(EduSchoolBb::getSchoolId,EduSchoolBb::getFullFlag).eq(EduSchoolBb::getYear,year)
                            .eq(EduSchoolBb::getSchoolId,result.getOrgId());
                    EduSchoolBb eduSchoolBb=eduSchoolBbService.getOne(bbQueryWrapper,false);
                    if(eduSchoolBb!=null){
                        result.setFullFlag(eduSchoolBb.getFullFlag()==null?"0":eduSchoolBb.getFullFlag());
                    }else{
                        result.setFullFlag("0");
                    }
                }
                if (bbTwoFlag) {
                    result.setEnrollStatus(EnrollStatusEnum.on.getType());
                    result.setStartTime(bbTwoOperation.getBegTime());
                    result.setEndTime(bbTwoOperation.getEndTime());
                    result.setBbFlag(BoolEnum.TRUE.getType());
                    //是否补报
                    QueryWrapper<EduSchoolBb> bbQueryWrapper=new QueryWrapper<>();
                    bbQueryWrapper.lambda().select(EduSchoolBb::getSchoolId,EduSchoolBb::getFullFlag).eq(EduSchoolBb::getYear,year)
                            .eq(EduSchoolBb::getSchoolId,result.getOrgId());
                    EduSchoolBb eduSchoolBb=eduSchoolBbService.getOne(bbQueryWrapper,false);
                    if(eduSchoolBb!=null){
                        result.setFullFlag(eduSchoolBb.getFullFlag()==null?"0":eduSchoolBb.getFullFlag());
                    }else{
                        result.setFullFlag("0");
                    }
                }
                if (qbFlag) {
                    result.setEnrollStatus(EnrollStatusEnum.on.getType());
                    result.setStartTime(qbOperation.getBegTime());
                    result.setEndTime(qbOperation.getEndTime());
                    result.setQbFlag(BoolEnum.TRUE.getType());
                }
                if (bmFlag) {
                    result.setEnrollStatus(EnrollStatusEnum.on.getType());
                    result.setStartTime(bmOperation.getBegTime());
                    result.setEndTime(bmOperation.getEndTime());
                }
                for (int i = 0; i < result.getConfigList().size(); i++) {
                    configList
                            .get(i)
                            .setEnrollStatus(result.getEnrollStatus());
                }
            }
        } else {
            result.setEnrollStatus(EnrollStatusEnum.finish.getType());
        }
        return result;
    }

    @Override
    @OpApi(funcCode = "eduschool0012", title = "根据学校id查询学校详情-不校验招生计划", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public EduSchoolVO getDetail(EduSchoolKeyVO vo) {
        if (StringUtils.isBlank(vo.getOrgId())) {
            throw new AppException("学校id不能为空");
        }
        EduSchoolVO result = eduSchoolService.getDetail(vo.getOrgId());
        if (ObjectUtils.isEmpty(result)) {
            throw new AppException("查询不到学校信息!");
        }
        return result;
    }

    /**
     * 保存前统一校验
     */
    @Override
    @OpApi(funcCode = "eduschool0003", title = "所属学校表保存前校验", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduSchoolVO vo) {
        //主键为空为新增校验

        //主键不为空为修改校验
    }

    @Override
    @OpApi(funcCode = "eduschool0004", title = "所属学校表新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduschool0004",
            operationName = "所属学校表新增",
            dataType = "orgId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduSchoolVO add(EduSchoolVO vo) {
        //保存前校验
        checkSave(vo);
        //保存数据
        EduSchool school = Convert.convert(EduSchool.class, vo);
        school.setOrgId(IdUtil.simpleUUID());
        school.setStatus("1");
        if (StringUtils.isNotBlank(school.getShortName())) {
            school.setShortName(Convert.toDBC(school.getShortName()));
        }
        school.setSchoolName(Convert.toDBC(school.getSchoolName()));
        eduSchoolService.save(school);
        //将主键设置回vo使操作日志可以取到
        vo.setOrgId(school.getOrgId());

        this.addOrg(school);
        clearCacheAreaCode(school.getAreaCode());
        return vo;
    }

    private void addOrg(EduSchool school) {
        QueryWrapper<SysOrg> schoolQueryWrapper = new QueryWrapper<>();
        schoolQueryWrapper.lambda().select(SysOrg::getOrgId,SysOrg::getParentId,SysOrg::getRate,SysOrg::getOrgId).eq(SysOrg::getOrgType, "0104")
                .eq(SysOrg::getAreaCode, school.getAreaCode())
                .eq(SysOrg::getStatus,BoolEnum.TRUE.getType())
                .eq(SysOrg::getFictitious,BoolEnum.TRUE.getType())
                .orderByAsc(SysOrg::getRate);
        List<SysOrg> prarentList = sysOrgService.list(schoolQueryWrapper);
        if (CollectionUtils.isEmpty(prarentList)){
            throw new AppException("请先维护该行政区划下的学校虚拟节点");
        }
        SysOrg parentOrg = prarentList.get(0);
        OrgVO org = Convert.convert(OrgVO.class, school);
        org.setOrgId(school.getOrgId());
        org.setStatus(school.getStatus());
        org.setOrgName(school.getSchoolName());
        org.setOrgCode(org.getOrgId());
        org.setOrgType("0104");
        org.setRate(3);
        org.setParentId(parentOrg.getOrgId());
        org.setTreeFlag(BoolEnum.FALSE.getType());
        org.setInsideFlag(BoolEnum.FALSE.getType());
        org.setHasAccount(BoolEnum.FALSE.getType());
        orgIntegration.add(org);
    }

    @Override
    @OpApi(funcCode = "eduschool0005", title = "所属学校表修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduschool0005",
            operationName = "所属学校表修改",
            dataType = "orgId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduSchoolVO edit(EduSchoolVO vo) {
        if (ObjectUtils.isEmpty(vo.getOrgId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        EduSchool oldEntity = eduSchoolService.getById(vo.getOrgId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }
        //保存前校验
        checkSave(vo);
        //保存数据
        if (StringUtils.isNotBlank(oldEntity.getShortName())) {
            oldEntity.setShortName(Convert.toDBC(oldEntity.getShortName()));
        }
        BeanUtil.copyProperties(vo, oldEntity, CopyOptions.create().ignoreNullValue());
        oldEntity.setSchoolName(Convert.toDBC(oldEntity.getSchoolName()));
        oldEntity.setStatus("1");
        eduSchoolService.updateById(oldEntity);
        SysOrg sysOrg = sysOrgService.getById(oldEntity.getOrgId());
        if (sysOrg == null) {
            this.addOrg(oldEntity);
        } else {
            sysOrg.setOrgName(oldEntity.getSchoolName());
            sysOrg.setStatus(oldEntity.getStatus());
            sysOrg.setOrgCode(oldEntity.getOrgId());
            sysOrg.setOrgType("0104");
            sysOrg.setAreaCode(oldEntity.getAreaCode());
            sysOrgService.updateById(sysOrg);
        }
        clearCache(vo.getOrgId());
        clearCacheForm(vo.getOrgId());
        clearCacheAreaCode(oldEntity.getAreaCode());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduschool0006", title = "所属学校表根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "eduschool0006",
            operationName = "所属学校表删除",
            dataType = "orgId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduSchoolKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getOrgId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduSchool entity = eduSchoolService.getById(vo.getOrgId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduSchoolService.removeById(vo.getOrgId());
        clearCache(vo.getOrgId());
        clearCacheForm(vo.getOrgId());
        clearCacheAreaCode(entity.getAreaCode());
    }

    @Override
    @OpApi(funcCode = "eduschool0007", title = "获取学校预报名统计信息", funcType = FuncTypeEnum.query)
    public PageInfo<EduSchoolVO> getSchoolStaData(EduSchoolQueryVO vo) {
        // 开启分页

        vo.setVirtualFlag(BoolEnum.FALSE.getType());
        vo.setStatus(BoolEnum.TRUE.getType());
        vo.setRecruitStatus(BoolEnum.FALSE.getType());
        if (vo.getPageNum() != null && vo.getPageSize() != null) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        }
        List<EduSchoolVO> eduSchoolList = querySchoolStaInfo(vo);
        List<String> streetList = eduSchoolList.stream().map(EduSchoolVO::getStreet).distinct().collect(Collectors.toList());
        QueryWrapper<EduArea> areaQueryWrapper = new QueryWrapper<>();
        areaQueryWrapper.lambda().in(EduArea::getLocalCode, streetList);
        List<EduArea> areaList =
                eduAreaService.list(areaQueryWrapper);

        Map<String, String> streetMap = areaList.stream().collect(Collectors.toMap(EduArea::getLocalCode, EduArea::getAreaName));
        for (EduSchoolVO eduSchoolVO : eduSchoolList) {
            if (!ObjectUtils.isEmpty(eduSchoolVO.getStreet())) {
                eduSchoolVO.setStreetName(streetMap.get(eduSchoolVO.getStreet()));
            }
        }

        if (CollectionUtils.isEmpty(eduSchoolList)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 转义数据字典值
        dictHelper.valueToName(eduSchoolList, Arrays.asList(SchoolDictEnum.values()));
        // 不为空则获取分页结果
        PageInfo<EduSchoolVO> pageInfo = new PageInfo<>(eduSchoolList);

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduschool0008", title = "根据行政区划获取学校地图上的信息", funcType = FuncTypeEnum.query, publicFlag = BoolEnum.TRUE, savelog = false)
    public List<EduSchoolMapVO> getSchoolMapList(EduSchoolMapQueryVO vo) {
        QueryWrapper<EduSchool> eduSchoolQueryWrapper = new QueryWrapper<>();
        eduSchoolQueryWrapper.lambda().select(EduSchool::getAreaCode, EduSchool::getOrgId, EduSchool::getSchoolName, EduSchool::getLatitude, EduSchool::getLongitude)
                .isNotNull(EduSchool::getLongitude).isNotNull(EduSchool::getLatitude)
                .eq(EduSchool::getRecruitStatus, BoolEnum.FALSE.getType()).eq(EduSchool::getStatus, BoolEnum.TRUE.getType())
                .eq(EduSchool::getAreaCode, vo.getAreaCode())
                .eq(StringUtils.isNotBlank(vo.getSchoolCategory()), EduSchool::getSchoolCategory, vo.getSchoolCategory())
                .eq(StringUtils.isNotBlank(vo.getSchoolNature()), EduSchool::getSchoolNature, vo.getSchoolNature())
                .like(StringUtils.isNotBlank(vo.getSchoolName()), EduSchool::getSchoolName, vo.getSchoolName());
        List<EduSchool> eduSchools = eduSchoolService.list(eduSchoolQueryWrapper);
        List<EduSchoolMapVO> resList = Convert.toList(EduSchoolMapVO.class, eduSchools);
        return resList;
    }

    @Override
    @OpApi(funcCode = "eduschool0009", title = "学校信息导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void downloadData(EduSchoolQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "eduschool0010", title = "手机端幼儿园可报名学校列表查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduSchoolVO> getAppNurserySchoolList(EduSchoolQueryVO vo) {
        List<String> areaCodeList = new ArrayList<>();
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(eduHelper.thisAreaCode());
            List<SelectVO> selectList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            if (selectList!= null && selectList.size() > 0){
                areaCodeList = selectList.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            }
        }else{
            areaCodeList.add(vo.getAreaCode());
        }
        vo.setSchoolCategory(SchoolCategoryEnum.KINDERGARTEN.getType());
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        List<EduSchoolVO> eduSchoolVOList = eduSchoolService.getAppSchoolByArea(areaCodeList);
        if (StringUtils.isNotBlank(vo.getSchoolName())) {
            vo.setSchoolName(Convert.toDBC(vo.getSchoolName()));
        }
        List<EduSchoolVO> allList = new ArrayList<>();
        long curTime = DateUtil.currentSeconds();
        for (EduSchoolVO eduSchoolVO : eduSchoolVOList) {
            if (!eduSchoolVO.getHasEnrollFlag()) {
                continue;
            }
            if (StringUtils.isNotBlank(vo.getSchoolName())) {
                if (eduSchoolVO.getSchoolName().indexOf(vo.getSchoolName()) < 0) {
                    continue;
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolCategory())) {
                if (!vo.getSchoolCategory().equalsIgnoreCase(eduSchoolVO.getSchoolCategory())) {
                    continue;
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolNature())) {
                if (!vo.getSchoolNature().equalsIgnoreCase(eduSchoolVO.getSchoolNature())) {
                    continue;
                }
            }
            if (!CollectionUtils.isEmpty(vo.getSchoolNatureList())) {
                if (!vo.getSchoolNatureList().contains(eduSchoolVO.getSchoolNature())) {
                    continue;
                }
            }
            if (!CollectionUtils.isEmpty(vo.getSchoolCategoryList())) {
                if (!vo.getSchoolCategoryList().contains(eduSchoolVO.getSchoolCategory())) {
                    continue;
                }
            }
            List<EduSchoolConfigVO> configList = eduSchoolVO.getConfigList();
            if (!CollectionUtils.isEmpty(configList)) {

                int stopNum = 0;
                Date startTime = eduSchoolVO.getConfigList().get(0).getStartTime();
                Date endTime = eduSchoolVO.getConfigList().get(0).getEndTime();
                for (int i = 0; i < configList.size(); i++) {
                    long startT = configList.get(i).getStartTime().getTime() / 1000;
                    long endT = configList.get(i).getEndTime().getTime() / 1000;
                    if (DateUtil.compare(
                            startTime, eduSchoolVO.getConfigList().get(i).getStartTime())
                            > 0) {
                        startTime = eduSchoolVO.getConfigList().get(i).getStartTime();
                    }
                    if (DateUtil.compare(endTime, eduSchoolVO.getConfigList().get(i).getEndTime())
                            < 0) {
                        endTime = configList.get(i).getEndTime();
                    }
                    if (DateUtil.compare(
                            configList.get(i).getEndTime(), DateUtil.date())
                            < 0) {
                        stopNum++;
                        configList
                                .get(i)
                                .setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        if (curTime < startT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.wait.getType());
                        } else if (curTime > endT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.finish.getType());
                        } else {
                            configList
                                    .get(i)
                                    .setEnrollStatus(EnrollStatusEnum.on.getType());
                        }
                    }
                }
                eduSchoolVO.setStartTime(startTime);
                eduSchoolVO.setEndTime(endTime);
                if (stopNum == configList.size()) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                } else {
                    long startT = startTime.getTime() / 1000;
                    long endT = endTime.getTime() / 1000;
                    if (curTime < startT) {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                    } else if (curTime > endT) {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    }
                }
                dictHelper.valueToName(
                        configList, Arrays.asList(SchoolConfigDictEnum.values()));

                eduSchoolVO.setConfigList(configList);
            } else {
                eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
            }
            allList.add(eduSchoolVO);

        }
        List<EduSchoolVO> retList = allList.stream().skip((vo.getPageNum() - 1) * vo.getPageSize()).limit(vo.getPageSize()).
                collect(Collectors.toList());
        PageInfo<EduSchoolVO> pageInfo = new PageInfo<>(retList);
        pageInfo.setPageNum(vo.getPageNum());
        pageInfo.setPageSize(vo.getPageSize());
        if (vo.getPageNum() == 1) {
            pageInfo.setIsFirstPage(true);
        } else {
            pageInfo.setIsFirstPage(false);
        }
        pageInfo.setTotal(retList.size());
        if (retList.size() == 0) {
            pageInfo.setHasNextPage(false);
            pageInfo.setPages(0);
        } else {
            Integer pages = (int) Math.ceil(retList.size() / vo.getPageSize());
            pageInfo.setPages(pages);
            if (pages <= vo.getPageNum()) {
                pageInfo.setHasNextPage(false);
                pageInfo.setIsLastPage(true);
            } else {
                pageInfo.setHasNextPage(true);
                pageInfo.setIsLastPage(false);
            }
        }

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduschool0011", title = "手机端义务段可报名学校列表查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduSchoolVO> getAppEnrollSchoolList(EduSchoolQueryVO vo) {
        List<String> areaCodeList = new ArrayList<>();
        if (StringUtils.isBlank(vo.getAreaCode())) {
            String areaCode = SessionUtil.getAreaCode();
            if (StringUtils.isBlank(areaCode)){
                areaCode = eduHelper.thisAreaCode();
            }
            vo.setAreaCode(areaCode);
            List<SelectVO> selectList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            if (selectList!= null && selectList.size() > 0){
                areaCodeList = selectList.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
                if (!areaCodeList.contains(eduHelper.thisAreaCode())){
                    areaCodeList.add(eduHelper.thisAreaCode());

                }
            }
        }else{
            areaCodeList.add(vo.getAreaCode());
        }
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        List<EduSchoolVO> eduSchoolVOList = eduSchoolService.getAppSchoolByArea(areaCodeList);
        if (StringUtils.isNotBlank(vo.getSchoolName())) {
            vo.setSchoolName(Convert.toDBC(vo.getSchoolName()));
        }

        List<EduSchoolVO> allList = new ArrayList<>();
        Integer year = eduHelper.thisYear();
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        if (eduOperationCacheVO == null) {
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO bmOperation = operation.get("YW002");//报名时间
        EduOperationCacheDetailVO bbOperation = operation.get("YW022");//补报时间
        EduOperationCacheDetailVO bbTwoOperation=operation.get("YW072");//第二批第二轮
        EduOperationCacheDetailVO qbOperation = operation.get("YW010");//抢报时间
        EduOperationCacheDetailVO mnOperation = operation.get("YW062");//模拟时间
        //判断是否报名业务期
        boolean bmFlag = bmOperation == null ? false : bmOperation.isFlag();
        //判断是否补报业务期
        boolean bbFlag = bmFlag || bbOperation == null ? false : bbOperation.isFlag();
        boolean bbTwoFlag = bmFlag || bbTwoOperation == null ? false : bbTwoOperation.isFlag();
        //判断是否空额抢报业务期
        boolean qbFlag = bmFlag || qbOperation == null ? false : qbOperation.isFlag();
        boolean mnFlag = mnOperation == null ? false : mnOperation.isFlag();
        long curTime = DateUtil.currentSeconds();
        for (EduSchoolVO eduSchoolVO : eduSchoolVOList) {
            if (!eduSchoolVO.getHasEnrollFlag()) {
                continue;
            }
            if (StringUtils.isNotBlank(vo.getSchoolName())) {
                if (eduSchoolVO.getSchoolName().indexOf(vo.getSchoolName()) < 0) {
                    continue;
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolCategory())) {
                if (!vo.getSchoolCategory().equalsIgnoreCase(eduSchoolVO.getSchoolCategory())) {
                    continue;
                }
            }
            if (StringUtils.isNotBlank(vo.getSchoolNature())) {
                if (!vo.getSchoolNature().equalsIgnoreCase(eduSchoolVO.getSchoolNature())) {
                    continue;
                }
            }
            if (StringUtils.isNotBlank(vo.getServiceFlag())) {
                if (!vo.getServiceFlag().equalsIgnoreCase(eduSchoolVO.getServiceFlag())) {
                    continue;
                }
            }
            if (!CollectionUtils.isEmpty(vo.getSchoolNatureList())) {
                if (!vo.getSchoolNatureList().contains(eduSchoolVO.getSchoolNature())) {
                    continue;
                }
            }
            if (!CollectionUtils.isEmpty(vo.getSchoolCategoryList())) {
                if (!vo.getSchoolCategoryList().contains(eduSchoolVO.getSchoolCategory())) {
                    continue;
                }
            }
            if (bbFlag && !BoolEnum.TRUE.getType().equalsIgnoreCase(eduSchoolVO.getBbFlag())) {
                continue;
            }
            if (bbTwoFlag && !BoolEnum.TRUE.getType().equalsIgnoreCase(eduSchoolVO.getBbFlag())) {
                continue;
            }
            if (qbFlag && !BoolEnum.TRUE.getType().equalsIgnoreCase(eduSchoolVO.getQbFlag())) {
                continue;
            }
            List<EduSchoolConfigVO> configList = eduSchoolVO.getConfigList();
            if (!CollectionUtils.isEmpty(configList)) {
                eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                if (bmOperation != null) {
                    if (!bmOperation.isFlag()) {
                        if ("1".equalsIgnoreCase(bmOperation.getType()) || "3".equalsIgnoreCase(bmOperation.getType())) {
                            eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                        } else {
                            if ("1".equalsIgnoreCase(bbOperation.getType())) {
                                //补报未开始
                                eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                eduSchoolVO.setBbFlag(BoolEnum.TRUE.getType());
                            } else if ("3".equalsIgnoreCase(bbOperation.getType())) {
                                eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                            } else {
                                if (bbTwoOperation!=null&&"1".equalsIgnoreCase(bbTwoOperation.getType())) {
                                    //抢报未开始
                                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                    eduSchoolVO.setQbFlag(BoolEnum.TRUE.getType());
                                } else {
                                    if (qbOperation!=null&&"1".equalsIgnoreCase(qbOperation.getType())) {
                                        //抢报未开始
                                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                                        eduSchoolVO.setQbFlag(BoolEnum.TRUE.getType());
                                    } else {
                                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                    }
                                }

                            }
                        }
                    }
                } else {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                }
                if(mnFlag){
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(mnOperation.getBegTime());
                    eduSchoolVO.setEndTime(mnOperation.getEndTime());
                    eduSchoolVO.setMnFlag(BoolEnum.TRUE.getType());
                }
                if (bbFlag) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(bbOperation.getBegTime());
                    eduSchoolVO.setEndTime(bbOperation.getEndTime());
                    eduSchoolVO.setBbFlag(BoolEnum.TRUE.getType());
                }

                if (bbTwoFlag) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(bbTwoOperation.getBegTime());
                    eduSchoolVO.setEndTime(bbTwoOperation.getEndTime());
                    eduSchoolVO.setBbFlag(BoolEnum.TRUE.getType());
                }
                if (qbFlag) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(qbOperation.getBegTime());
                    eduSchoolVO.setEndTime(qbOperation.getEndTime());
                    eduSchoolVO.setQbFlag(BoolEnum.TRUE.getType());
                }
                if (bmFlag) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(bmOperation.getBegTime());
                    eduSchoolVO.setEndTime(bmOperation.getEndTime());
                }

            } else {
                if(mnFlag){
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    eduSchoolVO.setStartTime(mnOperation.getBegTime());
                    eduSchoolVO.setEndTime(mnOperation.getEndTime());
                    eduSchoolVO.setMnFlag(BoolEnum.TRUE.getType());
                }else{
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                }
            }
            if (EnrollStatusEnum.on.getType().equalsIgnoreCase(eduSchoolVO.getEnrollStatus())&&!CollectionUtils.isEmpty(configList)) {
                int stopNum = 0;
                Date startTime = eduSchoolVO.getConfigList().get(0).getStartTime();
                Date endTime = eduSchoolVO.getConfigList().get(0).getEndTime();
                for (int i = 0; i < configList.size(); i++) {
                    long startT = configList.get(i).getStartTime().getTime() / 1000;
                    long endT = configList.get(i).getEndTime().getTime() / 1000;
                    if (DateUtil.compare(
                            startTime, eduSchoolVO.getConfigList().get(i).getStartTime())
                            > 0) {
                        startTime = eduSchoolVO.getConfigList().get(i).getStartTime();
                    }
                    if (DateUtil.compare(endTime, eduSchoolVO.getConfigList().get(i).getEndTime())
                            < 0) {
                        endTime = configList.get(i).getEndTime();
                    }
                    if (DateUtil.compare(
                            configList.get(i).getEndTime(), DateUtil.date())
                            < 0) {
                        stopNum++;
                        configList
                                .get(i)
                                .setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        if (curTime < startT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.wait.getType());
                        } else if (curTime > endT) {
                            configList
                                    .get(i)
                                    .setEnrollStatus(
                                            EnrollStatusEnum.finish.getType());
                        } else {
                            configList
                                    .get(i)
                                    .setEnrollStatus(EnrollStatusEnum.on.getType());
                        }
                    }
                }
                eduSchoolVO.setStartTime(startTime);
                eduSchoolVO.setEndTime(endTime);
                if (stopNum == configList.size()) {
                    eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                } else {
                    long startT = startTime.getTime() / 1000;
                    long endT = endTime.getTime() / 1000;
                    if (curTime < startT) {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.wait.getType());
                    } else if (curTime > endT) {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.finish.getType());
                    } else {
                        eduSchoolVO.setEnrollStatus(EnrollStatusEnum.on.getType());
                    }
                }
            }
            dictHelper.valueToName(
                    configList, Arrays.asList(SchoolConfigDictEnum.values()));

            eduSchoolVO.setConfigList(configList);
            allList.add(eduSchoolVO);

        }
        List<EduSchoolVO> retList = allList.stream().skip((vo.getPageNum() - 1) * vo.getPageSize()).limit(vo.getPageSize()).
                collect(Collectors.toList());
        PageInfo<EduSchoolVO> pageInfo = new PageInfo<>(retList);
        pageInfo.setPageNum(vo.getPageNum());
        pageInfo.setPageSize(vo.getPageSize());
        if (vo.getPageNum() == 1) {
            pageInfo.setIsFirstPage(true);
        } else {
            pageInfo.setIsFirstPage(false);
        }
        pageInfo.setTotal(retList.size());
        if (retList.size() == 0) {
            pageInfo.setHasNextPage(false);
            pageInfo.setPages(0);
        } else {
            Integer pages = (int) Math.ceil(retList.size() / vo.getPageSize());
            pageInfo.setPages(pages);
            if (pages <= vo.getPageNum()) {
                pageInfo.setHasNextPage(false);
                pageInfo.setIsLastPage(true);
            } else {
                pageInfo.setHasNextPage(true);
                pageInfo.setIsLastPage(false);
            }
        }

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduschool0013", title = "判断是否管理员账号", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE)
    public Boolean managerCheck(EduSchoolKeyVO vo) {

        String orgId=SessionUtil.getOrgId();
        if(StringUtils.isBlank(orgId)){
            throw new AppException("请先联系管理员分配单位");
        }
        EduSchool eduSchool=eduSchoolService.getById(orgId);
        if (eduSchool==null){
            return true;
        }
        return false;
    }


    private void setData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduSchoolQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            PageInfo<EduSchoolVO> pageInfo;
            if (vo.getModelCode().equals("schoolInfo")) {
                pageInfo = getList(vo);
            } else if (vo.getModelCode().equals("schoolStaInfo")) {
                pageInfo = getSchoolStaData(vo);
            } else {
                throw new AppException("导出类型未开发相应功能");
            }
            String total = String.valueOf(pageInfo.getTotal());
            List<Map<String, Object>> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduSchoolVO eduSchoolVO : pageInfo.getList()) {
                    list.add(BeanUtil.beanToMap(eduSchoolVO, false, true));
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    private List<EduSchoolVO> querySchoolStaInfo(EduSchoolQueryVO vo) {
        boolean permissionFlag = true;
        if (vo.getPermissionFlag() != null) {
            permissionFlag = vo.getPermissionFlag();
        }
        if (!ObjectUtils.isEmpty(vo.getSearchText())) {
            vo.setSchoolName(vo.getSearchText());
        }
        Map<String, Object> queryMap = BeanUtil.beanToMap(vo, false, true);
        Set<String> systemPrivileges = SessionUtil.getSystemPrivileges();
        if (!permissionFlag
                || systemPrivileges.contains(SysPermissionEnum.allorg.getType())
                || systemPrivileges.contains(SysPermissionEnum.superadmin.getType())) {

        } else {
            queryMap.put("userId", SessionUtil.getUserId());
        }
        //根据任务判断是否当前年度处理过迁移数据
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),handleTable);
        if (!queryHistoryFlag) {
            return eduSchoolService.querySchoolStaInfo(queryMap);
        }else {
            return eduSchoolService.querySchoolStaInfoHistory(queryMap);
        }
    }


    private List<EduSchoolVO> querySchoolInfo(EduSchoolQueryVO vo) {
        boolean permissionFlag = true;
        if (vo.getPermissionFlag() != null) {
            permissionFlag = vo.getPermissionFlag();
        }
        if (!ObjectUtils.isEmpty(vo.getSearchText())) {
            vo.setSchoolName(vo.getSearchText());
        }
        Map<String, Object> queryMap = BeanUtil.beanToMap(vo, false, true);
        Set<String> systemPrivileges = SessionUtil.getSystemPrivileges();
        if (!permissionFlag
                || systemPrivileges.contains(SysPermissionEnum.allorg.getType())
                || systemPrivileges.contains(SysPermissionEnum.superadmin.getType())) {

        } else {
            //查出账号配置的行政区划及子级行政区划
            List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(new DictAreaVO());
            List<String> areaList = districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaList.contains(sessionAreaCode)){
                areaList.add(sessionAreaCode);
            }
            if (areaList.size() >0 ){
                queryMap.put("areaList",areaList);
            }
        }
        Integer year = vo.getYear();
        if (year == null) {
            year = eduHelper.thisYear();
        }
        if (!ObjectUtils.isEmpty(vo.getCheckBrochure()) && vo.getCheckBrochure()) {
            queryMap.put("year", year);
        }
        if (BoolEnum.TRUE.getType().equals(vo.getBbFlag())) {
            queryMap.put("year", year);
        }
        // 开启分页
        if (vo.getPageNum() != null && vo.getPageSize() != null) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        }
        return eduSchoolService.selectSchoolList(queryMap);
    }

    private void clearCache(String orgId) {
        if (StringUtils.isNotBlank(orgId)) {
            Cache cache = JetCacheUtils.create(EduCache.EDU_SCHOOL_DETAIL, CacheType.BOTH);
            if (cache != null) {
                cache.remove(orgId);
            }
        }
    }

    private void clearCacheAreaCode(String areaCode) {
        if (StringUtils.isNotBlank(areaCode)) {
            Cache cache = JetCacheUtils.create(EduCache.EDU_SCHOOL_areaCode, CacheType.BOTH);
            if (cache != null) {
                cache.remove(areaCode);
            }
        }
    }

    private void clearCacheForm(String schoolId) {
        if (StringUtils.isNotBlank(schoolId)) {
            Cache cache = JetCacheUtils.create(EduCache.EDU_ENROLL_FORM_SCHOOL, CacheType.BOTH);
            if (cache != null) {
                cache.remove(schoolId);
            }
        }
    }
}
